/*
* @Author: ZHELIHAO\fangshuqin
* @Date:   2018-05-15 18:11:50
* @Last Modified by:   ZHELIHAO\fangshuqin
* @Last Modified time: 2018-05-26 19:45:50
*/
{
    let EVENT_CLICK = Laya.Event.CLICK;

    class Rolenum extends ui.Info.RolenumUI{
        constructor() {
            super();
            this.init();
        }

        init(){
            this.registerActions();
            this.initConfig();
            this.heroListAll = [];
            this.lastCheck = 0;
        }

        initConfig() {
             this.config = {
                MAX_WIDTH: 198,
                MIN_WIDTH: 25

            }
        }

        registerActions() {

            this.ACTIONS = {
                [GAME_CMDS.GETHEROLIST] : this.userRoleNum,
            };
            Sail.io.register(this.ACTIONS, this);

        }

        userRoleNum(data) {
             console.log("getHeroList", data);
            let result =[];
            let _length = data.length;
            let _odd = Math.floor( (_length+1)/2 );
            this.list_role_all.height = _length< 7 ? 355 * _odd :1060;
            this.list_role_all.vScrollBarSkin = "";

            data.forEach((item,index)=>{
                let _heroList = item;
                let _grade = Math.floor( _heroList.grade /5 );


                let _shadow = _heroList.had;

                // 英雄基本信息
                let heroNo = Number(_heroList.hero_no);
                let localHero = Sail.store.getHeroData(heroNo);

                // 英雄段位数据
                let heroGrade = Number(_heroList.grade);
                let localHeroGrade = Sail.store.getHeroGrade(heroGrade);

                // 段位
                let grade_mole = _heroList.cup_num - localHeroGrade.cup_num;  //分子
                    grade_mole > 0 ? grade_mole : 0 ;
                let grade_deno = localHeroGrade.next_cup_num;          //分母
                let grade_progress = grade_mole / grade_deno;

                let grade_per = Math.floor( grade_progress * 100 );
                let grade_w = grade_per / 100 * this.config.MAX_WIDTH;

                grade_w = grade_w < this.config.MIN_WIDTH ? this.config.MIN_WIDTH : grade_w; 

                result.push({
                    quality: {
                        skin:`res/public/frame_${localHero.quality}.png`
                        },
                    quality2: {
                        skin:`res/public/rolebg_${localHero.quality}.png`
                        },
                    role:{
                        skin:`res/public/role_${_heroList.hero_no}.png`
                        },
                    level: _heroList.level + '级',
                    progress:{
                        width:grade_w
                    },
                    cupnum: _heroList.cup_num,
                    grade:{
                        index : _grade
                    },
                    gradenum:_heroList.grade,
                    shadow : {
                        visible: _shadow == 0 ? true :false
                    }
                })

                // 遮罩：多余box隐藏
                    let hideBox  =  this.list_role_all.getCell(index);
                    let bg_pro = hideBox.getChildByName("bg_pro");
                    let bg_cup = hideBox.getChildByName("bg_cup");
                    let progress = hideBox.getChildByName("progress");
                    let cupnum = hideBox.getChildByName("cupnum");
                    let grade = hideBox.getChildByName("grade");
                    let gradenum = hideBox.getChildByName("gradenum");
                    let bg_lvl = hideBox.getChildByName("bg_lvl");
                    let level = hideBox.getChildByName("level");
                if(_shadow ==0){
                    bg_pro.visible = false;
                    bg_cup.visible = false;
                    progress.visible = false;
                    cupnum.visible =false;
                    grade.visible =false;
                    gradenum.visible = false;
                    bg_lvl.visible = false;
                    level.visible = false;
                    
                }else{
                    bg_pro.visible = true;
                    bg_cup.visible = true;
                    progress.visible = true;
                    cupnum.visible =true;
                    grade.visible =true;
                    gradenum.visible = true;
                    bg_lvl.visible = true;
                    level.visible = true;
                }
                
                
            })

            this.list_role_all.array = result;

        }
 
        exit () {
            Sail.io.unregister(this.ACTIONS);
        }
    }

    Sail.class(Rolenum, "Com.Info.Rolenum");
}